<template>
	<view class="all">
		<view class="top">
			<view class="head">
				<image class="top-image" :src="slist[0].listPhoto"
					mode="widthFix" />
				<view class="textInfo">
					<view class="text">
						歌单
					</view>
					<view class="time">
						{{time}}
					</view>
				</view>
			</view>
			<view class="zhongjian">
				<text class="zi">推荐歌单({{slist.length}})</text>
			</view>
		</view>
		<view>
			<view class="itemInfo">
				<view class="songListItem">
					<view class="list1" @tap="toSongList(item.listId)" v-for="item in slist" :key="item.listId">
						<view class="list1Pho">
							<image :src="item.listPhoto" class="listItem"></image>
						</view>
						<view>
							<text class="listTex">{{item.listTittle}}</text>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view style="height: 60rpx;"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				options2: [{
					text: '加入播放列表',
					style: {
						backgroundColor: '#3c9cff'
					}
				}, {
					text: "加入歌单",
					style: {
						backgroundColor: "#D9AFD9",
					}
				}],
				slist: [],
				code: Number,
				time: ""
			};
		},
		methods: {
			async getInfo() {
				const {
					data: res
				} = await uni.$http.get("/list/findRandom")
				console.log(res);
				if (res.code != 200) {
					uni.showToast({
						title: "获取信息失败",
						duration: 1000,
						position: 'center',
						icon: 'error'
					})
				}
				this.slist = res.data
				this.code = res.code
				let time = new Date()
				let nowTime = this.timestampToTime(time.toLocaleString('en-US', {
					hour12: false
				}).split(" "))
				this.time = nowTime
			},
			timestampToTime(times) {
				console.log(times);
				let month = times[1]
				let day = times[2]
				let tim = times[4]
				return  month + '-' + day + ' ' + tim
			},
			toSongList(item) {
				uni.navigateTo({
					url: "/subpkg/toSongList/toSongList?listId=" + item
				})
			},
			async getListById(id) {
				const {
					data: res
				} = await uni.$http.get("/list/findListById?listId="+id)
				console.log(res);
				if (res.code != 200) {
					uni.showToast({
						title: "获取信息失败",
						duration: 1000,
						position: 'center',
						icon: 'error'
					})
				}
				this.slist = res.data
				this.code = res.code
				let time = new Date()
				let nowTime = this.timestampToTime(time.toLocaleString('en-US', {
					hour12: false
				}).split(" "))
				this.time = nowTime
			},
			async getLikeById(id) {
				const {
					data: res
				} = await uni.$http.get("/list/findListLikeById?listLikeId="+id)
				console.log(res);
				if (res.code != 200) {
					uni.showToast({
						title: "获取信息失败",
						duration: 1000,
						position: 'center',
						icon: 'error'
					})
				}
				this.slist = res.data
				this.code = res.code
				let time = new Date()
				let nowTime = this.timestampToTime(time.toLocaleString('en-US', {
					hour12: false
				}).split(" "))
				this.time = nowTime
			},
		},
		onLoad(e) {	
			if(e.listId!=null){
				this.getListById(e.listId)
			}else if(e.likelistId!=null){
				this.getLikeById(e.likelistId)
			}else{
				this.getInfo()
			}
		}
	}
</script>

<style lang="scss">
	.top {
background-color: #FAACA8;
background-image: linear-gradient(180deg, #FAACA8 0%, #DDD6F3 57%, #f0f0f0 96%);
	}

	.textInfo {
		margin-left: 35rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		height: 130rpx;
	}

	.text {
		margin-left: 30rpx;
		font-family: 宋体;
		font-size: 50rpx;
		font-weight: bolder;
	}

	.time {
		color: #5c5c5c;
		margin-left: 16rpx;
	}

	.head {
		width: 100%;
		height: 340rpx;
		display: flex;
		margin-left: 80rpx;
		align-items: center;
	}

	.top-image {
		width: 250rpx;
		border-radius: 20rpx;
	}

	.head {
		height: 500rpx;
		height: 500rpx;

	}

	.zhongjian {
		padding: 10rpx 30rpx;
		border-top: 2rpx solid gray;
		border-bottom: 2rpx solid gray;

		.zi {
			font-size: 35rpx;
			font-weight: 600;
			margin: 20rpx 40rpx;
		}
	}

	.scroll-item {
		padding-top: 20rpx;
		display: flex;
		background-color: #f0f0f0;
		/* justify-content: space-around; */
	}

	.song-number {
		width: 80rpx;
		line-height: 100rpx;
		text-align: center;
		font-size: 45rpx;
		margin-left: 20rpx;
		font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
		color: rgba(100, 98, 98, 0.8);
	}

	.scroll-item .song-info {
		position: relative;
		flex: 1;
		max-width: 50%;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		margin-bottom: 3px;
	}

	.song-info .song-title {
		font-size: 36rpx;
		color: #111;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.song-info .song-desc {
		font-size: 28rpx;
		color: #5c5c5c;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}


	.song-info .song-desc .bgimg {
		width: 60rpx;
		margin-right: 5rpx;
	}

	.s {
		position: absolute;
		right: 60rpx;
		margin-top: 10px;
	}

	.songListItem {
		display: flex;
		flex-flow: wrap;
		justify-content: space-around;
	}

	.listItem {
		width: 290rpx;
		height: 290rpx;
		border-radius: 15%;
		box-shadow: 10rpx 10rpx 10rpx rgba(0, 0, 0, .2);
	}

	.list1 {
		margin-top: 20rpx;
		display: inline-block;
		width: 290rpx;
	}

	.listTex {
		width: 100%;
		font-size: 30rpx;
		// word-wrap: break-word;
		// word-break: normal;
		display: -webkit-box;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: pre-wrap;
		-webkit-line-clamp: 1;
		-webkit-box-orient: vertical;
		margin-top: 20rpx;
		font-weight: 550;
	}
</style>
